package com.antoco.operation.bigscreen.service.autogeneration.impl;

import com.antoco.operation.bigscreen.repository.TjZtRepository;
import com.antoco.operation.bigscreen.model.entity.TjZt;
import com.antoco.operation.bigscreen.service.autogeneration.intf.TjZtService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Service
@Transactional
public class TjZtServiceImpl extends AbstractModelServiceImpl implements TjZtService {
    private final TjZtRepository repository;

    public TjZtServiceImpl(TjZtRepository repository) {
        this.repository = repository;
    }

    @Override
    public TjZt save(TjZt entity) {
        return repository.save(entity);
    }

    @Override
    public List<TjZt> save(List<TjZt> entities) {
        return (List<TjZt>) repository.saveAll(entities);
    }

    @Override
    public void deleteById(String id) {
        repository.deleteById(id);
    }

    @Override
    public Optional<TjZt> findById(String id) {
        return repository.findById(id);
    }

    @Override
    public List<TjZt> findAll() {
        return (List<TjZt>) repository.findAll();
    }

    @Override
    public Page<TjZt> findAll(Pageable pageable) {
        Page<TjZt> entityPage = repository.findAll(pageable);
        List<TjZt> entities = entityPage.getContent();
        return new PageImpl<>(entities, pageable, entityPage.getTotalElements());
    }

    @Override
    public TjZt update(TjZt entity, String id) {
        Optional<TjZt> optional = findById(id);
        if (optional.isPresent()) {
            return save(entity);
        }
        return null;
    }
}